package cn.edu.tju.core.security.repository;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import cn.edu.tju.core.model.User;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {

   @EntityGraph(attributePaths = "authorities")
   Optional<User> findOneWithAuthoritiesByUsername(String username);

   Optional<User> findOneByUsername(String username);

   //查找所有未删除的用户
   List<User> findByDeletedFalse();

   //根据用户名查找未删除的用户
   @EntityGraph(attributePaths = "authorities")
   Optional<User> findOneWithAuthoritiesByUsernameAndDeletedFalse(String username);

   //根据ID查找未删除的用户
   @EntityGraph(attributePaths = "authorities")
   Optional<User> findByIdAndDeletedFalse(Long id);

   // 统计用户总数（未删除的）
   long countByDeletedFalse();
}
